package com.swipemaster.game;

public class StaticClockFace
{
	/** Lookup table for 10 digits. */
	private static final char[] digits = "0123456789".toCharArray();
	/** Initial clock face. */
	private static final char[] initClockFace = "     0.0".toCharArray();
	/** Length of clock face. */
	public static final int LENGTH = initClockFace.length;
	/** Space for changing time. 6 leading digits (indices: 0 to 5) and 1 digit precision (index: 7). */
	private static final char[] clockFace = new char[LENGTH];

	public static int getStartIndex()
	{
		for (int i = 0; i < LENGTH; i++)
		{
			if (clockFace[i] != ' ')
			{
				return i;
			}
		}
		// Unreachable, because there is always a '.' on the clock face.
		return 0;
	}

	public static char[] getTimeToDraw(double timeToDraw)
	{
		System.arraycopy(initClockFace, 0, clockFace, 0, LENGTH);

		int time = (int) timeToDraw;

		final int lastDigit = (int) (10 * timeToDraw) % 10;
		final char lastdigitChar = digits[lastDigit];
		clockFace[LENGTH - 1] = lastdigitChar;

		for (int i = 5; (i >= 0) && (time != 0); i--)
		{
			clockFace[i] = digits[time % 10];
			time /= 10;
		}

		return clockFace;
	}
}
